package com.itheima.admin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.admin.dto.SensitivePageDto;
import com.itheima.admin.mapper.AdSensitiveMapper;
import com.itheima.admin.pojo.AdSensitive;
import com.itheima.admin.service.AdSensitiveService;
import com.itheima.common.vo.PageResultVo;
import com.itheima.common.vo.ResultVo;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.PostMapping;

@Service
public class AdSensitiveServiceImpl extends ServiceImpl<AdSensitiveMapper, AdSensitive> implements AdSensitiveService {

    /**
     * 敏感词分页查询
     *
     * @param dto
     * @return
     */
    @Override

    public PageResultVo<AdSensitive> pageList(SensitivePageDto dto) {
        //1.构建分页参数
        IPage<AdSensitive> iPage = new Page<>(dto.getPage(), dto.getSize());
        //2.构建分页条件
        LambdaQueryWrapper<AdSensitive> lqw = new LambdaQueryWrapper<>();
        //3.设置分页参数
        lqw.like(dto.getSensitives() != null, AdSensitive::getSensitives, dto.getSensitives());
        //4.执行分页查询
        page(iPage, lqw);
        //5.响应分页参数
        return PageResultVo.pageResult(iPage.getPages(), iPage.getSize(), iPage.getTotal(), iPage.getRecords());
    }


}
